<?php
include_once '../includes/common.php';
if($islogin2==1){}else sysmsg("您还未登录，请先登录",2,'./login.php',true);
$title='自助余额转换';
include_once './header.php';
if($conf['user_toMoney_open']!=1)showmsg('错误', '授权平台未开放自助余额转换功能！', 4, './');
?>
<div class="row">
    <div class="col-lg-12">
        <div class="card">
            <div class="card-header">
                自助余额转换
            </div>
            <div class="card-body">
                <div class="layui-elem-quote">如果你需要使用可提现余额来消费，可使用此功能把可提现余额转换成不可提现余额<hr>注意:可提现余额转换成不可提现余额后不可提现，只能用于消费哦</div>
                <form class="form-horizontal layui-form">
                    <div class="form-group mb-3">
                        <label for="example-input-normal" style="font-weight: 500">转换金额：<span class="badge badge-danger-lighten">可提现余额：<?php echo round($userrow['rmb_tc'],2)?>元</span></label>
                        <input type="text" class="form-control" name="money" placeholder="输入要转换不可提现余额的金额" lay-verType="tips" lay-verify="required">
                    </div>
                    <button type="submit" class="btn btn-block btn-xs btn-outline-success" lay-submit lay-filter="submit_toMoney">转 换</button>
                </form>
            </div>
        </div>
        <div class="card">
            <div class="card-header">
                余额转换记录
            </div>
            <div class="card-body">
                <div style="white-space:nowrap;overflow-x: auto;">
                    <table class="layui-table layuiadmin-page-table">
                        <thead><tr><th>转换金额</th><th>转换时间</th><th>状态</th></tr></thead>
                        <tbody>
                        <?php
                        $flag=false;
                        $rs=$DB->query("SELECT * FROM authguao_points WHERE uid='{$userrow['uid']}' AND action='转换' ORDER BY id DESC LIMIT 10");
                        while($res = $DB->fetch($rs))
                        {
                        $flag=true;
                        echo '<tr><td><b>'.$res['point'].'</b></td><td>'.$res['addtime'].'</td><td><font color="green">已完成</font></td></tr>';
                        }
                        if(!$flag)echo '<tr class="no-records-found"><td colspan="99">暂无转换记录</td></tr>';
                        ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<?php
include_once './bottom.php';
?>
<script type="text/javascript">
layui.use(['form'], function () {
    var form = layui.form;
    form.on('submit(submit_toMoney)', function (data) {
        layer.alert('是否要执行当前操作？', {
            icon: 3, btn: ['确定', '取消'], btn1: function (layero, index) {
                toMoney();
            }
        });
        return false;
    });
});
function toMoney(){
    var money = $("input[name='money']").val();
    $.ajax({
        type : "POST",
        url : "ajax.php?act=toMoney",
        data : {money:money},
        dataType : 'json',
        async: true,
        success : function(data) {
            if(data.code == 0){
                layer.msg(data.msg, {
                    icon: 6,
                    end: function (layero, index) {
                        window.location.reload();
                    }
                });
            } else {
                layer.msg(data.msg, {icon: 5});
            }
        }
        error:function(data){
            layer.msg('服务器错误', {icon: 5});
            return false;
        }
    });
    return false;
}
</script>